<!doctype html>
<html class="no-js">
<head>
    <title>ZTE 中兴金融科技</title>
    {{include 'base/style.html'}}
    <link rel="stylesheet" href="{{=URL('static','module/login/css/app.css')}}">
</head>
<style>
</style>
<body data-type="login" style="background: #334054;">
<button id="close" type="button" class=" am-close am-close-spin">&times;</button>
<div class="am-g myapp-login">
    <div class="myapp-login-bg">
        <div class="myapp-login-logo-text">
            手机号注册
        </div>
        <form id="form" action="" class="am-form">
            <fieldset>
                <div class="am-form-group">
                    <label for="username">手机号</label>
                    <input type="text" id="username" minlength="11" maxlength="11" placeholder="请输入手机号" class="am-form-field"
                           required/>
                </div>
                <div class="am-form-group">
                    <label for="password">密码</label>
                    <input type="password" id="password" minlength="1" placeholder="请输入密码" class="am-form-field"
                           required/>
                </div>
                <div>
                    <label for="password2">确认密码</label>
                    <input type="password" id="password2" minlength="1" placeholder="请输入确认密码" class="am-form-field" required/>
                </div>
                <div class="am-form-group myapp-login-treaty"><label class="am-form-label"></label><label
                        class="am-checkbox-inline"> <input id="checkbox" type="checkbox" minchecked="2"
                                                           maxchecked="4" required>已同意使用条约 </label></div>
                <button id="register_btn" class="myapp-login-button am-btn am-btn-secondary" type="button">注 册</button>
            </fieldset>
            <legend>已有账号 <a href="{{=URL('finance','login')}}?type={{=request.vars.type}}">去登录</a></legend>
        </form>


    </div>
</div>


<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">该手机号已注册，请直接登录</div>
      <div class="am-modal-bd"></div>
    <div class="am-modal-footer">
      <span class="am-modal-btn">确定</span>
    </div>
  </div>
</div>
<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert-sc">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">注册成功，请直接登录</div>
      <div class="am-modal-bd"></div>
    <div class="am-modal-footer">
      <span class="am-modal-btn">确定</span>
    </div>
  </div>
</div>


{{include 'base/jsFile.html'}}
<script>
    var temp = "{{=request.vars.type}}";
    var url = "{{=URL('finance','mind')}}";
    if (temp == 1) {
        url = "{{=URL('finance','myassets')}}";
    }
    $('#close').click(function () {
        window.location.href = url;
    })


    $('#register_btn').click(function () {
       var username= document.getElementById("username");
       var pass1 = document.getElementById("password");
       var pass2 = document.getElementById("password2");
       var checkbox = document.getElementById("checkbox");
       if(username.value==""){
            username.setCustomValidity("手机号不能为空");
       }else{
            var re = /^1\d{10}$/
            if (re.test(username.value)) {
                username.setCustomValidity("");
            } else {
                username.setCustomValidity("手机格式不正确");
            }
       }

        if(pass1.value=="")
            pass1.setCustomValidity("密码不能为空");
        else{
            if (pass1.value != pass2.value) {
                pass1.setCustomValidity("两次输入的密码不匹配");
            } else {
                pass1.setCustomValidity("");
            }
        }

        if(!checkbox.checked)
            checkbox.setCustomValidity("同意继续")
        else
            checkbox.setCustomValidity("")

        if(document.getElementById("form").checkValidity()){
           data_param={"username":username.value, "password":pass1.value}
            $.ajax({//http://10.204.127.36:8000/appweb/v1/test/1.json
                //url:"{{=URL('v1','user')}}/1.json",
                url:"{{=URL('v1','user')}}",
                type: "POST",
                data:JSON.stringify(data_param),
                headers:{
                    "cube_user_token":"123token",
                    "Content-Type":"application/json"
                },
                contentType: 'text/html; charset=UTF-8',
                dataType: "json",
                success: function(data) {
                   //alert(JSON.stringify(data)); // Object
                    if(data.id!=null){
                        $('#my-alert-sc').modal();
                    }else{
                        $('#my-alert').modal();
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
        //            alert(XMLHttpRequest.status);
        //            alert(XMLHttpRequest.readyState);
                    alert(errorThrown);
                },
                complete: function(XMLHttpRequest, textStatus) {
                }

            });

        }



    })



//    var $modal = $('#my-alert');
//        $modal.modal();
//        setTimeout(function(){$modal.modal('close');},1000);



</script>
</body>
</html>